package com.apes.hr.salary.rewardPunish.repository;

import com.apes.framework.jpa.repository.CustomRepository;
import com.apes.hr.base.model.Employee;
import com.apes.hr.salary.rewardPunish.model.RewardPunish;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

import java.util.Date;
import java.util.List;

/**
 * @author HuJianLin
 * @create 2018-05-09 16:07
 */
public interface RewardPunishRepository extends CustomRepository<RewardPunish, String>{



    @Query(value =
            "select A.* from HR_REWARD_PUNISH T, HR_REWARD_PUNISH_ITEM A WHERE T.ID = A.REWARD_PUNISH_ID and t.reward_date>=?1 and t.state ='sendOut' and A.EMPLOYEE_ID =?2"
            ,nativeQuery = true)
    List<Object> findByRewardDate(Date oldYear,Employee employee);

//    @Query(
//            "select T from RewardPunish T  join t.rewardPunishItems A WHERE T.rewardDate>=?1 and t.state ='sendOut' "
//          )
//    List<RewardPunish> findByRewardDate2(Date oldYear,Employee employee);

    @Query("select T from RewardPunish T where 1 = 1 and (id like %:value% or explain like %:value%) ")
    Page<RewardPunish> find(@Param("value") String value, Pageable pageable);

    @Query("select T from RewardPunish T where 1 = 1 and (id like %:value% or explain like %:value%) and state ='sendOut' ")
    Page<RewardPunish> findByState(@Param("value") String value, Pageable pageable);

    @Query("select T from RewardPunish T where 1 = 1 and (id like %:value% or explain like %:value%) and state ='sendOut' ")
    Page<RewardPunish> rewardPunishAppealFind(@Param("value") String value, Pageable pageable);
    @Modifying
    @Query(value = "UPDATE hr_Reward_Punish T set t.create_date =to_date(?2,'YYYY-MM-DD HH24:MI:SS'),t.send_out_date = to_date(?2,'YYYY-MM-DD HH24:MI:SS') where t.id = ?1 ",nativeQuery = true)
    void updateCreateDate(String id ,String createDate);
}
